package com.example.springboot.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页查询结果的封装工具类
 * @Author:wzf
 * @Data:2022/2/21
 * @Version:1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class PageBean<T> {
  private Integer currentPage = 1;
  // 每页显示的总条数
  private Integer pageSize = 10;
  // 总条数
  private Integer totalNum;
  // 是否有下一页
  private Integer isMore;
  // 总页数
  private Integer totalPage;
  // 开始索引
  private Integer startIndex;
  // 分页结果
  private ArrayList<T> items;


  public PageBean(Integer currentPage, Integer pageSize, Integer totalNum) {
    super();
    this.currentPage = currentPage;
    this.pageSize = pageSize;
    this.totalNum = totalNum;
    this.totalPage = (this.totalNum + this.pageSize - 1) / this.pageSize;
    this.startIndex = (this.currentPage - 1) * this.pageSize;
    this.isMore = this.currentPage >= this.totalPage ? 0 : 1;
  }
}
